<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>住户管理</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/js/global.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
         .left ul li{
			
			*line-height:40px;
			*background:#484848;
			*padding-left:20px;
		}
		
		.left ul li a, .left ul li a:hover{
			*color:#fff;
		}
		.panel,.jqGrid_wrapper{
			*+margin-left:270px;
		}
		.btn{
		*+width:60px;
		}
		.lt{
			float:left;
        	text-align: center;					
		}
		.form-group{
			*+overflow:hidden;
		}

    </style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
 	<div class="wrapper">
        <div class="panel panel-default">
            <div class="panel-heading">
                <span><strong>查询条件</strong></span>

                <div class="ibox-tools">
                    <a class="collapse-link"> <i class="fa fa-chevron-down"></i></a>
                    <a class="collapse-link  d-n"> <i class="fa fa-chevron-up"></i></a>
                </div>
            </div>
            <div class="panel-body">
                <form class="form-horizontal">
                	<div class="form-group">
                		<label class="selectlabe1 col-md-1 form-lable lt">公司名称：</label>
                        <div class="selectdivs col-md-3 lt">
                            <select name="agtCode" id="agtCode" class="form-control col-md-1"></select>
                        </div>
              			<label class="selectlabe1 col-md-1 form-lable lt">应用：</label>
                        <div class="selectdivs col-md-3 lt">
                            <select name="funcMainId" id="funcMainId" class="form-control col-md-1" style="text-align: center;">
                            	<option value="" >&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp请选择</option>
                            	<option value="1">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp物业缴费</option>
                            	<option value="2">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp停车缴费</option>
                            	<option value="3">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp水费缴费</option>
                            </select>
                        </div>
                         <div class="col-md-1 form-action lt" >
		                <button class="btn btn-success form-control" id="query">查询</button>
		           		</div>
		           		<div class="col-md-1 form-action lt">
		                <button class="btn btn-success form-control" id="resetForm">清空</button>
		           		</div>
         			</div>
                </form>
            </div>
        </div>

	    <div class="jqGrid_wrapper">
	        <div id="jqGrid_operation" class="jg-grid">
	            <div class="jqGrid_operation" id="action"></div>
	        </div>
	        <table id="jqGrid"></table>
	        <div id="jqGrid_paper"></div>
	    </div>
    </div>
</div>
<script>
$(document).ready(
        function () {
            $.jgrid.defaults.styleUI = "Bootstrap";
                $("#jqGrid").jqGrid({
                      url: "${pageContext.request.contextPath}/admin/funcMain_page4audit.action",
                      mtype: 'POST',
                      datatype: "json",
                      height: 350,
                      autowidth: true,
                      shrinkToFit: true,
                      rowNum: 10,
                      rowList: [10, 20, 30],
                      colNames: ['序号','区域','公司', '应用名称', '申请时间', '审核时间',
                          '审核人', '总小区数', '已开通数', '操作'],
                      colModel: [{
                          name: "SID",
                          index: "SID",
                          key: true,
                          hidden: true
                      }, {
                          name: 'DESCRIBED',
                          index: 'DESCRIBED',
                          width: 90
                      }, {
                          name: 'AGTNAME',
                          index: 'AGTNAME',
                          width: 90
                      }, {
                          name: 'FUNCNAME',
                          index: 'FUNCNAME',
                          width: 90
                      }, {
                          name: "LASTAPPLYTIME",
                          index: "LASTAPPLYTIME",
                          width: 80
                      }, {
                          name: 'LASTAUDITTIME',
                          index: 'LASTAUDITTIME',
                          width: 80
                      },{
                          name: 'LASTAUDITUSERNAME',
                          index: 'LASTAUDITUSERNAME',
                          width: 80
                      },{
                          name: "ALL",
                          index: "ALL",
                          width: 80
                      },{
                          name: "OPEN",
                          index: "OPEN",
                          width: 80
                      },{
                          name: 'SID',
                          index: 'SID',
                          width: 80,
                          formatter: function (cellvalue, options, rawObject) {
                        	  if(cellvalue=='-1' || !cellvalue){
	                              	return '';
	                          }else{
	                               	return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="审核" onclick="audit('+rawObject.SID+')"/>'+'<input type="button" style="padding: 2px 10px;margin-left:5px" class="btn btn-success" value="详情" onclick="view('+rawObject.SID+')"/>';
		                      }
                              
                       	  }
                      }],
                      sortname: 't.sid',
                      sortorder:'desc',
                      rownumbers: true,
                      jsonReader: {
                          root: 'rows',
                          page: "page",
                          total: 'total',
                          records: "records",
                          repeatitems: false
                      },
                      pager: "#jqGrid_paper",
                      viewrecords: true,
                      multiselect: true,
                      hidegrid: false,
                      loadComplete: function(){
                    		var re_records = Number($("#jqGrid").getGridParam('records'));
                    		var page = Number($("#jqGrid").getGridParam('page'));
                    		var rows=Number($("#jqGrid").getGridParam('rowNum'));
                    		var num = re_records-(page-1)*rows;
                    		if(num < rows)
                    		{
                    			for(var i=num;i<rows;i++){
                    				$("#jqGrid").jqGrid("addRowData",(i+1),
                            				{ "SID":"","STATUS":"-1"}
                    				,"");
                    			}
                    			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
                    		}
                    	}
                  });
            
                
                $.post("${pageContext.request.contextPath}/admin/tagent_list.action", function (data) {
		            $("#agtCode").empty();
		            $("#agtCode").append("<option value=''>请选择公司</option>");
		            for (var i = 0; i < data.length; i++) {
		                $("#agtCode").append("<option value='" + data[i].agtCode + "'>" + data[i].agtName + "</option>");
		            }
		            $("#agtCode").select2({
		                "placeholder": "请选择公司",
		                "width": "100%"
		            })
		       
		        }, "json");
                
            <!--查询-->
            jQuery("#query").click(query);
            jQuery("#resetForm").click(resetForm);
        });
$("#funcMainId").select2({
  	 "placeholder": "请选择",
       "minimumResultsForSearch":-1
  })
    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }
    function query() {
        var $agtCode = $("#agtCode").val();
        var $funcMainId = $("#funcMainId").val();
        
        $("#jqGrid").jqGrid('setGridParam', {
            url: "${pageContext.request.contextPath}/admin/funcMain_page4audit.action",
            postData: {
                'agtCode': $agtCode,
                'funcMainId': $funcMainId
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入*/
        return false;
    }
    
    
    function audit(sid){
    	layer.open({
            type: 2,
            title: '<strong>审核应用</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['600px', '580px'],
            content: '${pageContext.request.contextPath}/admin/funcMain_auditView.action?sid='
            + sid,
            btn: ['通过','拒绝', '取消'],
            yes: function (index, layero) {
                
                var communityids='';
                var applyids='';
                var sid=$("#layui-layer-iframe" + index).contents().find("#sid").val();
                $("#layui-layer-iframe" + index).contents().find("input[name='applyid']:checkbox:checked").each(function(){ //选中的小区
                	var applyid = $(this).val();
                	
                	applyids+=applyid+",";
                	
                });
                if(applyids==''){
                	layer.alert("请勾选至少一条数据", {
                        icon: 6,
                        closeBtn: false
                    });
            		return;
                }
                $.post("${pageContext.request.contextPath}/admin/funcMain_audit.action",'applyids='+applyids+'&result=yes',function(data){
                     if (data.code == 1) {
                         layer.alert(data.msg, function () {
                             layer.closeAll();
                             refreshGrid();
                         });
                     } else {
                         layer.alert(data.msg);
                     }
                  },'json');
            },
            btn2: function (index, layero) {
                
                var communityids='';
                var applyids='';
                var sid=$("#layui-layer-iframe" + index).contents().find("#sid").val();
                $("#layui-layer-iframe" + index).contents().find("input[name='applyid']:checkbox:checked").each(function(){ //选中的小区
                	var applyid = $(this).val();
                	
                	applyids+=applyid+",";
                	
                });
                if(applyids==''){
                	layer.alert("请勾选至少一条数据", {
                        icon: 6,
                        closeBtn: false
                    });
            		return;
                }else{
                	 layer.prompt({
                   	  formType: 2,
                   	  title: '拒绝理由',
                   	  area: ['200px', '300px'] //自定义文本域宽高
                   	}, function(value, index, elem){
                   		if(value==''){
                   			layer.alert("请填写理由", {
                                   icon: 6,
                                   closeBtn: false
                               });
                   		}else{
                   			layer.close(index);	
                   			$.post("${pageContext.request.contextPath}/admin/funcMain_audit.action",'applyids='+applyids+'&result=no&comment='+value,function(data){
                                   if (data.code == 1) {
                                       layer.alert(data.msg, function () {
                                           layer.closeAll();
                                           refreshGrid();
                                       });
                                   } else {
                                       layer.alert(data.msg);
                                   }
                                },'json');
                   		}
                       
                     });
                }
               
                
            },btn3: function(index, layero){
                layer.close(index);
            }
        });
    }
    
    
    function view(sid){
    	layer.open({
            type: 2,
            title: '<strong></strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['1000px', '580px'],
            content: '${pageContext.request.contextPath}/admin/funcMain_viewDetailByAdmin.action?sid='
            + sid,
            btn: ['关闭'],
            yes: function (index, layero) {
                layer.close(index)
            }
        });
    }
    
    
    function resetForm() {
        location.reload();
        return false;
    }
    function post(url,params) {
    	var temp = document.createElement("form");
    	temp.action = url;
    	temp.method = "post";
    	temp.style.display = "none";
    	for (var x in params) {
    	var opt = document.createElement("textarea");
    	opt.name = x;
    	opt.value = params[x];
    	temp.appendChild(opt);
    	}
    	document.body.appendChild(temp);
    	temp.submit();
    	return temp;
    }
	
	if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length >>> 0;
    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;
    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  }
};
window.onload=function(){
	
	function BrowserType(){
		//获取浏览器的userAgent代理号；
		var userAgent=navigator.userAgent;
		
		//判断是否是Opera浏览器
		var isOpera=userAgent.indexOf("Opera")>-1;
		//判断是否是IE浏览器
		var isIE=userAgent.indexOf("compatible")>-1 && userAgent.indexOf("MSIE")>-1 && !isOpera;
		//判断是否是IE7浏览器
		if(isIE){
			var relIE=new RegExp("MSIE(\\d+\\.\\d+);");
			
			relIE.test(userAgent);
			var arr=userAgent.split(";")
			var flEVersion=arr[1].indexOf("7");
			if(flEVersion>-1){
				
				$tr=$("thead tr th");
				$td=$("tbody tr td");
				var len=$tr.length;
				for(var i=0;i<len;i++){
					$tr[i].style.width=10+"px";
					$td[i].style.width=10+"px";
				};
			}
		}
	};
	BrowserType();
};
	
</script>
</body>
</html>
